//
//  DoneInforVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/1/6.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "DoneInforVC.h"
#import "GifVC.h"
#import "WSDatePickerView.h"

@interface DoneInforVC ()<UITextFieldDelegate>
@property (strong, nonatomic) IBOutlet UILabel *titleLab;

@property (strong, nonatomic) IBOutlet UIButton *jump_btn;
@property (strong, nonatomic) IBOutlet LGTextField *nameField;
@property (strong, nonatomic) IBOutlet UIButton *manBtn;
@property (strong, nonatomic) IBOutlet UIButton *womanBtn;

@property (strong, nonatomic) IBOutlet UILabel *label2;

@property (strong, nonatomic) IBOutlet UIButton *birthday_btn;
@property (strong, nonatomic) IBOutlet UIButton *tiJiaoBtn;
@property (strong, nonatomic) IBOutlet UIImageView *back_img;
@property (strong, nonatomic) IBOutlet UIView *back_view;

@end

@implementation DoneInforVC{
    NSString *birthday;//生日日期
    NSString *gender;//性别 1 男 2 女 0未知
    RequestServices *service;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.backKuang setHidden:YES];
    [self.titleView setHidden:YES];
    self.back_img.image = [UIImage imageNamed:@"log_center"];
    [self.back_view insertSubview:self.back_img atIndex:0];
    //设置字体适应
    [self setFontSize];
    [self.nameField layoutMyTextField];
    //提交
    [self.tiJiaoBtn addTarget:self action:@selector(pushVC) forControlEvents:UIControlEventTouchUpInside];
    service = [[RequestServices alloc]initWithDelegate:self];
    gender = @"0";
    
    self.nameField.delegate = self;
    NSAttributedString *attrString = [[NSAttributedString alloc] initWithString:@"请输入昵称" attributes:@{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:self.nameField.font}];
    self.nameField.attributedPlaceholder = attrString;
    APPViewBorderRadius(self.nameField, 10, 1, [UIColor whiteColor]);
    APPViewBorderRadius(self.birthday_btn, 10, 1, [UIColor whiteColor]);
}
- (IBAction)chooseBirthday:(UIButton *)sender {
    [self.view endEditing:YES];
    WSDatePickerView *datepicker = [[WSDatePickerView alloc]initWithDateStyle:DateStyleShowYearMonthDay CompleteBlock:^(NSDate *date) {
        self->birthday = [date stringWithFormat:@"yyyy-MM-dd"];
        [sender setTitle:self->birthday forState:UIControlStateNormal];
    }];
    datepicker.doneButtonColor = [UIColor colorWithHexString:Select_line_Color];
    [datepicker show];
}


-(void)setFontSize{
    self.titleLab.font = AutoLabFont1;
    self.label2.font = self.manBtn.titleLabel.font = self.womanBtn.titleLabel.font = self.nameField.font = self.birthday_btn.titleLabel.font = self.tiJiaoBtn.titleLabel.font = AutoLabFont2;
    self.jump_btn.titleLabel.font = AutoLabFont3;
}



//提交按钮
-(void)pushVC{
    [self.view endEditing:YES];
    if (![self.nameField.text CheckNSStringData]) {
        [self ShowNewMsg:@"请输入昵称"];
        return;
    }
    if (![self->birthday CheckNSStringData]) {
        [self ShowNewMsg:@"请选择生日"];
        return;
    }
    [service registerCount:self.nameField.text gender:gender birthday:birthday tag:8000];
}

#pragma mark - requestDelegate
-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    if (tag == 8000) {
        [self ShowNewMsg:@"注册成功"];
        [self SkipLogin:1];
    }    
}

-(void)getError:(NSError *)error tag:(long long)tag{
    [self ShowNewMsg:error.domain];
}


- (void)SkipLogin:(NSInteger)type
{
    [self.view endEditing:YES];
    AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication] delegate];
    BaseNavVC * nav = [[BaseNavVC alloc]init];
    nav.view.backgroundColor = [UIColor whiteColor];
    appDelegate.window.rootViewController = nav;
    appDelegate.nav = nav;
}

/*
* 选择男 
*/
- (IBAction)chooseMan:(UIButton *)sender {
    gender = @"1";
    [sender setImage:[UIImage imageNamed:@"dot_icon_s"] forState:UIControlStateNormal];
    [self.womanBtn setImage:[UIImage imageNamed:@"dot_icon_n"] forState:UIControlStateNormal];
}

/*
 * 选择女
 */
- (IBAction)chooseWoman:(UIButton *)sender {
    gender = @"2";
    [sender setImage:[UIImage imageNamed:@"dot_icon_s"] forState:UIControlStateNormal];
    [self.manBtn setImage:[UIImage imageNamed:@"dot_icon_n"] forState:UIControlStateNormal];
}

/*
 * 跳过
 */
- (IBAction)jump:(id)sender {
    [self SkipLogin:1];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
